#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    //freopen("in.txt", "r", stdin);
    char x[15][15];
    char x2[15][15];
    char x3[15][15];
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cin >> x[i][j];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cin >> x2[i][j];
        }
    }
    int flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x[i][j] != x2[j][n - i + 1])
                flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("1");
        return 0;
    }
    flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x[i][j] != x2[n - i + 1][n - j + 1])
                flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("2");
        return 0;
    }
    flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x[i][j] != x2[n - j + 1][i])
                flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("3");
        return 0;
    }
    flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x[i][j] != x2[i][n - j + 1])
                flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("4");
        return 0;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            x3[i][n - j + 1] = x[i][j];
        }
    }
    flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x3[i][j] != x2[j][n - i + 1])
                flag = 1;
        }
    }
    if(flag == 0)
    {
        printf("5");
        return 0;
    }
    flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x3[i][j] != x2[n - i + 1][n - j + 1])
                flag = 1;
        }
    }
    if(flag == 0)
    {
        printf("5");
        return 0;
    }
    flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x3[i][j] != x2[n - j + 1][i])
                flag = 1;
        }
    }

    if (flag == 0)
    {
        printf("5");
        return 0;
    }
    flag = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x[i][j] != x2[i][j])
                flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("6");
        return 0;
    }
    else
    {
        printf("7");
        return 0;
    }
}